<?php

/**
 * @file
 *   
 * EM Registration Validate for Form steps.
 */

function _register_em_demographic_info_validate($form, &$form_state) {
    $values = $form_state['values'];
    
    $username_validation = user_validate_name($values['username']);
    $email_validation = user_validate_mail($values["email"]);
    
    if (!empty($username_validation)) {
        form_set_error('username', t($username_validation));
    }
    else if(user_load_by_name($values['username'])){
        form_set_error('username', t("Username already exists."));
    }
    
    if (!empty($email_validation)) {
        form_set_error('email', t($email_validation));
    }
    else if(user_load_by_mail($values["email"])){
        form_set_error('email', t("Email address already registered with another user."));
    }
    
    if (strlen($values['password']) < 5) {
        form_set_error('password', t('Password must be more than 4 characters'));
    }
    else if ($values['password'] != $values['confirm_password']) {//confirm_password
        form_set_error('password', t("Password and Confirm Password do not match"));
    }
}

function _register_em_address_validate($form, &$form_state) {
    $values = $form_state['values'];
    $form_key = "em_addresses";
    
    foreach ($values[$form_key] as $address_data) {
        
    }
}

function register_em_eligibility_validate($form, &$form_state) {
    
}